package xiaohongshu

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"marketing-server/global"
	"marketing-server/model/common/response"
	"marketing-server/model/marketing/xiaohongshu"
	xiaohongshuReq "marketing-server/model/marketing/xiaohongshu/request"
)

type XhsAccessTokenApi struct{}

// CreateXhsAccessToken 创建xhsAccessToken表
// @Tags XhsAccessToken
// @Summary 创建xhsAccessToken表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsAccessToken true "创建xhsAccessToken表"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /xhsAccessToken/createXhsAccessToken [post]
func (xhsAccessTokenApi *XhsAccessTokenApi) CreateXhsAccessToken(c *gin.Context) {
	var xhsAccessToken xiaohongshu.XhsAccessToken
	err := c.ShouldBindJSON(&xhsAccessToken)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = xhsAccessTokenService.CreateXhsAccessToken(&xhsAccessToken)
	if err != nil {
		global.MS_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("创建成功", c)
}

// DeleteXhsAccessToken 删除xhsAccessToken表
// @Tags XhsAccessToken
// @Summary 删除xhsAccessToken表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsAccessToken true "删除xhsAccessToken表"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /xhsAccessToken/deleteXhsAccessToken [delete]
func (xhsAccessTokenApi *XhsAccessTokenApi) DeleteXhsAccessToken(c *gin.Context) {
	id := c.Query("id")
	err := xhsAccessTokenService.DeleteXhsAccessToken(id)
	if err != nil {
		global.MS_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("删除成功", c)
}

// DeleteXhsAccessTokenByIds 批量删除xhsAccessToken表
// @Tags XhsAccessToken
// @Summary 批量删除xhsAccessToken表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /xhsAccessToken/deleteXhsAccessTokenByIds [delete]
func (xhsAccessTokenApi *XhsAccessTokenApi) DeleteXhsAccessTokenByIds(c *gin.Context) {
	ids := c.QueryArray("ids[]")
	err := xhsAccessTokenService.DeleteXhsAccessTokenByIds(ids)
	if err != nil {
		global.MS_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("批量删除成功", c)
}

// UpdateXhsAccessToken 更新xhsAccessToken表
// @Tags XhsAccessToken
// @Summary 更新xhsAccessToken表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body marketing.XhsAccessToken true "更新xhsAccessToken表"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /xhsAccessToken/updateXhsAccessToken [put]
func (xhsAccessTokenApi *XhsAccessTokenApi) UpdateXhsAccessToken(c *gin.Context) {
	var xhsAccessToken xiaohongshu.XhsAccessToken
	err := c.ShouldBindJSON(&xhsAccessToken)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	err = xhsAccessTokenService.UpdateXhsAccessToken(xhsAccessToken)
	if err != nil {
		global.MS_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:"+err.Error(), c)
		return
	}
	response.OkWithMessage("更新成功", c)
}

// FindXhsAccessToken 用id查询xhsAccessToken表
// @Tags XhsAccessToken
// @Summary 用id查询xhsAccessToken表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query marketing.XhsAccessToken true "用id查询xhsAccessToken表"
// @Success 200 {object} response.Response{data=marketing.XhsAccessToken,msg=string} "查询成功"
// @Router /xhsAccessToken/findXhsAccessToken [get]
func (xhsAccessTokenApi *XhsAccessTokenApi) FindXhsAccessToken(c *gin.Context) {
	id := c.Query("id")
	rexhsAccessToken, err := xhsAccessTokenService.GetXhsAccessToken(id)
	if err != nil {
		global.MS_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:"+err.Error(), c)
		return
	}
	response.OkWithData(rexhsAccessToken, c)
}

// GetXhsAccessTokenList 分页获取xhsAccessToken表列表
// @Tags XhsAccessToken
// @Summary 分页获取xhsAccessToken表列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query marketingReq.XhsAccessTokenSearch true "分页获取xhsAccessToken表列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /xhsAccessToken/getXhsAccessTokenList [get]
func (xhsAccessTokenApi *XhsAccessTokenApi) GetXhsAccessTokenList(c *gin.Context) {
	var pageInfo xiaohongshuReq.XhsAccessTokenSearch
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := xhsAccessTokenService.GetXhsAccessTokenInfoList(pageInfo)
	if err != nil {
		global.MS_LOG.Error("获取失败!", zap.Error(err))
		response.FailWithMessage("获取失败:"+err.Error(), c)
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     pageInfo.Page,
		PageSize: pageInfo.PageSize,
	}, "获取成功", c)
}

// GetXhsAccessTokenPublic 不需要鉴权的xhsAccessToken表接口
// @Tags XhsAccessToken
// @Summary 不需要鉴权的xhsAccessToken表接口
// @accept application/json
// @Produce application/json
// @Param data query marketingReq.XhsAccessTokenSearch true "分页获取xhsAccessToken表列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /xhsAccessToken/getXhsAccessTokenPublic [get]
func (xhsAccessTokenApi *XhsAccessTokenApi) GetXhsAccessTokenPublic(c *gin.Context) {
	// 此接口不需要鉴权
	// 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
	xhsAccessTokenService.GetXhsAccessTokenPublic()
	response.OkWithDetailed(gin.H{
		"info": "不需要鉴权的xhsAccessToken表接口信息",
	}, "获取成功", c)
}
